package hospital;

public class HW4 {
    //多人参加千米长跑，（多个线程），每人速度不同，
    //人到终点时，给出名次。
    //类似老吴 第1名
    //老张 第2名
    public static void main(String[] args) {
        myThread t1=new myThread(5,"老吴");
        myThread t2=new myThread(5,"老李");
        myThread t3=new myThread(5,"张三");
        myThread t4=new myThread(5,"李四");
        t1.setName("老吴");
        t2.setName("老李");
        t3.setName("张三");
        t4.setName("李四");

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}

class myThread extends Thread{
    private int speed;
    private String name;
    static int rank=0;
    public myThread(int speed,String name){
        this.speed=speed;
        this.name=name;
    }


    @Override
    public void run(){
        int distance=1000;
        while (true){
            distance=distance-speed;
            if(distance<=0){
                synchronized (myThread.class){
                    rank++;
                    System.out.println(getName()+"第"+rank+"名");
                    break;
                }
            }
            try {
                Thread.sleep((long) (10.0/speed));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}